class WSGIResponse(object):
    def __init__(self, headers, content, http_status):
        self.http_headers = headers
        self.content = content
        self.http_status = http_status
        self.cookies = []

    def send(self, start_response):
        headers = self.http_headers.items()
        for cookie in self.cookies:
            headers.append (("Set-cookie", cookie))
        start_response(self.http_status, headers)
        return self.content

    def set_cookie(self, name, value, max_age, domain=None, path=None, http_only=None, secure=None):
        cookie_value = name + "=" + value
        if max_age is not None:
            cookie_value += "; Max-age=" + str(max_age)
        if domain is not None:
            cookie_value += "; Domain=" + domain
        if path is not None:
            cookie_value += "; Path=" + path
        self.cookies.append(cookie_value)
        
class WSGIHtmlResponse(WSGIResponse):
    def __init__(self, headers, content):
        headers['content-type'] = "text/html"
        WSGIResponse.__init__(self, headers, content, "200 OK")

class WSGIJsonResponse(WSGIResponse):
    def __init__(self, headers, content):
        headers['content-type'] = "text/plain"
        WSGIResponse.__init__(self, headers, content, "200 OK")

class WSGIRedirectResponse(WSGIResponse):
    def __init__(self, url):
        headers = {}
        headers['location'] = url
        WSGIResponse.__init__(self, headers, '', "301 redirect")
